package com.ruoyi.financial.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.financial.domain.FBanker;
import com.ruoyi.financial.service.IFBankerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 庄家Controller
 *
 * @author ruoyi
 * @date 2025-02-08
 */
@RestController
@RequestMapping("/financial/banker")
public class FBankerController extends BaseController {
    @Autowired
    private IFBankerService fBankerService;

    /**
     * 查询庄家列表
     */
    @PreAuthorize("@ss.hasPermi('financial:banker:list')")
    @GetMapping("/list")
    public TableDataInfo list(FBanker fBanker) {
        startPage();
        List<FBanker> list = fBankerService.selectFBankerList(fBanker);
        return getDataTable(list);
    }

    @GetMapping
    public R<List<FBanker>> lists(FBanker fBanker) {
        List<FBanker> list = fBankerService.selectFBankerList(fBanker);
        return R.ok(list);
    }

    /**
     * 导出庄家列表
     */
    @PreAuthorize("@ss.hasPermi('financial:banker:export')")
    @Log(title = "庄家", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FBanker fBanker) {
        List<FBanker> list = fBankerService.selectFBankerList(fBanker);
        ExcelUtil<FBanker> util = new ExcelUtil<FBanker>(FBanker.class);
        util.exportExcel(response, list, "庄家数据");
    }

    /**
     * 获取庄家详细信息
     */
    @PreAuthorize("@ss.hasPermi('financial:banker:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(fBankerService.selectFBankerById(id));
    }

    /**
     * 新增庄家
     */
    @PreAuthorize("@ss.hasPermi('financial:banker:add')")
    @Log(title = "庄家", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FBanker fBanker) {
        return toAjax(fBankerService.insertFBanker(fBanker));
    }

    /**
     * 修改庄家
     */
    @PreAuthorize("@ss.hasPermi('financial:banker:edit')")
    @Log(title = "庄家", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FBanker fBanker) {
        return toAjax(fBankerService.updateFBanker(fBanker));
    }

    /**
     * 删除庄家
     */
    @PreAuthorize("@ss.hasPermi('financial:banker:remove')")
    @Log(title = "庄家", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fBankerService.deleteFBankerByIds(ids));
    }
}
